#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

#include "appengine.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    // QQmlApplicationEngine engine;
    AppEngine *engine = AppEngine::getInstance();

    const QUrl url(QStringLiteral("qrc:/CompoundMechine_15Axis/main.qml"));
    QObject::connect(
        engine,
        &QQmlApplicationEngine::objectCreated,
        &app,
        [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        },
        Qt::QueuedConnection);
    engine->load(url);

    QObject::connect(&app, &QGuiApplication::aboutToQuit, [](){
        AppEngine::destroyInstance(); // 调用销毁方法，触发析构
    });

    return app.exec();
}
